// pages/mail/mailadmin.js
Page({
  mixins: [require('../mixin/themeChanged')],

  /**
   * 页面的初始数据
   */
  data: {
  
  stime:"",
  etime:"",
  list:[],

  },

  bindStimeChange: function (e) {
    this.setData({
      stime: e.detail.value
    })
    this.bindDateChange()
  },

  bindEtimeChange: function (e) {
    this.setData({
      etime: e.detail.value
    })
    this.bindDateChange()
  },


  bindDateChange: function () {
    var that = this
    var url = wx.getStorageSync("config")
    var city = wx.getStorageSync("city")

    wx.request({
      url: url.service.homeUrl + '/mail/showmailorder',
      data: {
        city: city,
        stime:that.data.stime,
        etime:that.data.etime,
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res) => {
   

        that.setData({
          list: res.data,
        })
      },
      fail: function (res) {},
      complete: function (res) {},
    })


  },



  changeMark: function (e) {
    var that = this
    var url = wx.getStorageSync("config")
    //得到当前点击数据的id号
    this.setData({
      currentid: e.currentTarget.dataset.id
    })
    console.log(e.currentTarget.dataset.id)


    wx.showModal({
      title: '删除确认',
      content: '请核对删除内容是否正确',
      success: function (res) {
        if (res.confirm) {


          //请求体
          wx.request({
            url: url.service.homeUrl + '/mail/changemailmark',
            data: {
              id: that.data.currentid,
              mark: 0
            },
            header: {
              'content-type': 'application/x-www-form-urlencoded'
            },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: (res) => {

              wx.showToast({
                title: res.data.msg,
              });

              that.bindDateChange()

            },
            fail: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
            complete: function (res) {
              wx.showToast({
                title: res.data.msg,
              })
            },
          })
        }
      }
    })
  },



  changeTheme: function() {
    console.log(this.data);
    getApp().themeChanged(this.data.theme === 'light' ? 'dark' : 'light');
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})